package com.liuc.practice.bank.transfer.utils;

import com.liuc.practice.bank.transfer.annotation.Autowired;
import com.liuc.practice.bank.transfer.annotation.Service;

import java.sql.SQLException;

/**
 * @Author Liu Chang
 * @Date 2021/3/11 5:39 下午
 */
@Service()
public class TransactionManager {

    @Autowired
    private ConnectionUtils connectionUtils;

    public void setConnectionUtils(ConnectionUtils connectionUtils) {
        this.connectionUtils = connectionUtils;
    }

    public void openTransaction() throws SQLException {
        connectionUtils.getConnectionFromCurrentThread().setAutoCommit(false);
    }

    public void commit() throws SQLException {
        connectionUtils.getConnectionFromCurrentThread().commit();
    }

    public void rollback() throws SQLException {
        connectionUtils.getConnectionFromCurrentThread().rollback();
    }
}
